﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using EasyXaf.MongoDB;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System.ComponentModel;

namespace EasyXaf.Sample.Module.BusinessObjects;

[DomainComponent]
[MongoEntity]
[DefaultClassOptions]
[XafDisplayName("部门")]
public class Department : MongoEntity
{
    private string _name;
    private string _description;

    [XafDisplayName("名称")]
    public string Name
    {
        get => _name;
        set => SetPropertyValue(ref _name, value);
    }

    [XafDisplayName("描述")]
    public string Description
    {
        get => _description;
        set => SetPropertyValue(ref _description, value);
    }

    [Browsable(false)]
    public ObjectId? CompanyId { get; set; }

    [BsonIgnore]
    [XafDisplayName("公司")]
    [MongoAssociation]
    [MongoForeignKey(nameof(CompanyId))]
    public Company Company
    {
        get => GetEntity<Company>();
        set => SetEntity(value);
    }
}
